/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.sys.sprache;

import java.util.Locale;

import org.xnap.commons.i18n.I18n;
import org.xnap.commons.i18n.I18nFactory;
import org.xnap.commons.i18n.I18nManager;
import org.xnap.commons.i18n.LocaleChangeListener;

/**
 * @author Michael Nitsche
 * 19.06.2010	Erstellt
 * 
 * http://code.google.com/p/gettext-commons/wiki/Tutorial
 * 
 * In jeder Klasse initialisieren mit:
 * 	 private S s=new S(getClass());
 *   private static final S s=new S(SC_Events.class);
 */
public class S {
	
	private static final String messages="po.Messages";
//	private static I18n i18n = I18nFactory.getI18n(GetTextTest.class, "mn.test.gettext.Messages", Locale.ENGLISH);
//	private static I18n i18n = I18nFactory.getI18n(getClass(), "mn.test.gettext.Messages", Locale.FRANCE, I18nFactory.FALLBACK);
//	private static I18n i18n = I18nFactory.getI18n(getClass(), messages, Locale.FRANCE, I18nFactory.FALLBACK);
	private final I18n i18n;
	private static Locale locale=Locale.getDefault();
	
	
	public S(Class<?> klasse) {
		this.i18n=I18nFactory.getI18n(getClass(), messages, locale, I18nFactory.FALLBACK);
		I18nManager.getInstance().add(this.i18n);
	}
	
	
	public static void sprache(Locale locale) {
		S.locale=locale;
		I18nManager.getInstance().setDefaultLocale(locale);
	}
	
	public static void eSprache(LocaleChangeListener listener) {
		I18nManager.getInstance().addLocaleChangeListener(listener);
	}
	
	
	public String t(String t) {
		return this.i18n.tr(t);
	}
}
